home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_03
/
9n03116b
< prev
next >
Wrap
Text File
|
1991-01-15
|
966b
|
54 lines
/*
* xr.c - a cross-reference generator
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xrt.h"
int getword(char *word, size_t lim)
{
int c;
char *w = word;
assert(lim > 2);
while (isspace(c = fgetc(stdin)) && c != '\n')
;
if (c != EOF)
*w++ = c;
if (!isalpha(c))
{
*w = '\0';
return c;
}
for ( ; lim-- > 0; ++w)
if (!isalnum(*w = fgetc(stdin)))
{
ungetc(*w, stdin);
break;
}
*w = '\0';
return *word;
}
#define MAXWORD 100
int main(void)
{
char word[MAXWORD];
unsigned lineno = 1;
while (getword(word, MAXWORD) != EOF)
if (isalpha(word[0]))
xrt_add(word, lineno);
else if (word[0] == '\n')
++lineno;
xrt_print();
return 0;
}